<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>考勤管理</title>
    <link rel="stylesheet" href="../../../layui/css/layui.css">
    <script src="../../../layui/layui.js"></script>
</head>
<style type="text/css">
    body{
        height: 100%;
        width: 100%;
        margin-top: 11px;
    }


</style>

<body >
<!-- 内容主体区域 -->
<div class="layui-fluid layui-form">
    <div class="layui-form-item">
        <div class="layui-input-inline " style=" width: 638px;">
            <!--<button class="layui-btn layui-btn-primary addMember">新增顾客</button>
            <button class="layui-btn updateMember">修改顾客</button>
            <button class="layui-btn layui-btn-normal deleteMember">删除顾客</button>-->
            <!--      <button class="layui-btn">默认按钮</button>
                  <button class="layui-btn layui-btn-normal">百搭按钮</button>-->
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width:70px">选择门店</label>
            <div class="layui-input-inline" id="qq">
                <select id="salon" name="salon">

                    <!--<option value="0571">杭州</option>-->
                </select>
            </div>
            <div class="layui-input-inline" id="date">
                <select id="time" name="time">
                    <option value="01">一月</option>
                    <option value="02">二月</option>
                    <option value="03">三月</option>
                    <option value="04">四月</option>
                    <option value="05">五月</option>
                    <option value="06">六月</option>
                    <option value="07">七月</option>
                    <option value="08">八月</option>
                    <option value="09">九月</option>
                    <option value="10">十月</option>
                    <option value="11">十一月</option>
                    <option value="12">十二月</option>
                </select>
            </div>
           <!-- <label class="layui-form-label">选择时间</label>
            <div class="layui-inline"> &lt;!&ndash; 注意：这一层元素并不是必须的 &ndash;&gt;
                <input type="text" class="layui-input" id="test1">
            </div>
-->
        </div>
        <div class="layui-inline">
          <!--  <div class="layui-input-inline">
                <input type="text" name="userKey" class="layui-input userKeyValue ">
            </div>-->
            <div class="layui-input-inline">
                <button class="layui-btn layuiadmin-btn-admin layui-btn-normal check" lay-submit="" lay-filter="LAY-user-back-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button></div>
        </div>
        <div class="layui-inline">
<!--            <div class="layui-input-inline">
                <input type="text" name="userKey" class="layui-input userKeyValue ">
            </div>-->
<!--            <div class="layui-input-inline" style="width: 38px;">
                <button class="layui-btn layuiadmin-btn-admin layui-btn-normal check" lay-submit="" lay-filter="LAY-user-back-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>

            </div>-->
            <div class="layui-input-inline" style="width: 179px;">
            <label class="layui-form-label">应出勤数：</label>
            <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                <input type="text" class="layui-input attendanceNum" style="width: 58px;"/>
            </div>
            </div>
            <div class="layui-input-inline" style="width: 179px;">
            <label class="layui-form-label">共出勤数：</label>
            <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                <input type="text" class="layui-input hasAttendanceNum" style="width: 58px;"/>
            </div>
            </div>
            <div class="layui-input-inline" style="width: 179px;">
            <label class="layui-form-label">异常数：</label>
            <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                <input type="text" class="layui-input yichangNum" style="width: 58px;"/>
            </div>
            </div>
            <!--<button class='layui-btn'>详情</button>-->
        </div>
    </div>
</div>

<div id="pTable" >
    <table id="layui_table_id" class="layui-table" lay-skin="line" lay-filter="test" style="width: 1680px">

    </table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>
        </script>
    <div id="laypage"></div>
</div>
</body>
</html>

<script type="text/javascript">

    layui.use(['form','laydate','layer','table','laypage','util','jquery'],function(){

        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#test1' //指定元素
        });
        var form = layui.form;
        var laydate=layui.laydate;
        var $ = layui.$;
        var myDate = new Date();
        var year =  myDate.getFullYear();    //获取完整的年份(4位,1970-????)
        var month = myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
        var date =  myDate.getDate();        //获取当前日(1-31)
        var time = year+"-"+month;
        if(month<10){
            month = "0"+month;
        }
        productsearch(1,"","",time);
        init();
        function init() {
            $.ajax({
                type:'get',
                url:'/hy/basic/timeSheet/getSalon',
                data:{page:1,limit:20},
                success: function(data){
                    var dataList =data.data;
                    var html="<option value=''>请选择门店</option>";
                    for(var i=0;i<dataList.length;i++){
                        html+="<option value='"+dataList[i].recordId+"'>"+dataList[i].salonName+"</option>";
                    }
                    $("#salon").append(html);
                    form.render('select');
                },
                error:function(data){
                    alert("操作失败");
                    console.log(data);
                }
            })
        }
        $("#time").find("option[value = '"+month+"']").attr("selected","selected");
        function productsearch(page,filterExpr,salonId,time) {

            var table = layui.table,
                laydate = layui.laydate,
                laypage = layui.laypage;
            var form = layui.form;
            table.render({
                elem : '#layui_table_id',
                url : '/hy/basic/timeSheet/getTimeSheetBySalonId',
                cols : [ [
                    {checkbox: true,
                        filter:'test'
                    }
                    ,
                    {
                        field : 'stuffId',
                        title : 'id',
                        sort : true,
                        align : 'center'
                    }
                    , {
                        field : 'stuffName',
                        title : '姓名',
                        align : 'center'
                    }
                    , {
                        field : 'tel',
                        title : '电话',
                        align : 'center'
                    }
                    , {
                        field : 'lateNum',
                        title : '迟到次数',
                        align : 'center'
                    }, {
                        field : 'leaveEarlyNum',
                        title : '早退次数',
                        align : 'center'
                    }
                    , {
                        field : 'absenceFromDutyNum',
                        title : '缺勤天数',
                        align : 'center'
                    }
                    , {
                        field : 'checkinOmission',
                        title : '签到遗漏',
                        align : 'center'
                    }
                    , {
                        field : 'signOmission',
                        title : '签退遗漏',
                        align : 'center'
                    }
                    , {
                        field : 'leaveNum',
                        title : '请假天数',
                        align : 'center'
                    }
                    ,{
                        title : '操作',
                        fixed: 'right',
                        align:'center',
                        toolbar: '#barDemo'}
                ] ],
                page : true,
                where : {
                    salonId:salonId,
                    time:time,
                    filterExpr:filterExpr,
                },
                responseHandler: function (res, curr,count) {
                    $('#pageNum').val(curr);
                    $(".attendanceNum").val(res.attendanceNum);
                    $(".hasAttendanceNum").val(res.hasAttendanceNum);
                    $(".yichangNum").val(res.yichangNum);
                   var salonId= res.salonId;
                    /*       var salonName = res.salonName;
                          var temp = "";
                          temp = "<option selected='selected' value="+salonId+">"+salonName+"</option>";
                          $("#salon").append(temp);*/


                    $("#salon").find("option[value = '"+salonId+"']").attr("selected","selected");
                    form.render();//表单重新渲染，要不然添加完显示不出来新的option
                    return {
                        "count": res.total,
                        "data": res.data,
                        "code": 0,//code值为200表示成功
                        "msg": ""
                    }
                },
                done : function(res, curr, count) {
                    console.log(res)
                    $('#pageNum').val(curr);

                }
            })


            // table.on('checkbox(test)', function(obj){
            //   console.log(layui.table.checkStatus('layui_table_id'));
            // });
            // 监听工具条
            table.on('tool(test)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data, //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == 'detail') {
                    queryById(data.id);
                } else if (layEvent == 'del') {
                    //alert(data.id)
                    var pageNum = $('#pageNum').val();
                    layer.confirm('真的删除行么', function(index){
                        layer.close(index);
                    });
                } else if (layEvent === 'edit') {
                    timeSeetingItem(data);
                }
            });
            //常规用法
            laydate.render({
                elem : '#initialStoreId'
            });
            //常规用法
            laydate.render({
                elem : '#processingTime'
            });

        }
        //搜索
        $(".check").on("click", function() {
           // productsearch(1,"123",2,"2019-03");
            var myDate=new Date();
            var time=$('#time option:selected').val();
            var year = myDate.getFullYear();
            var temp  = year+"-"+time;
            var salonId = $('#salon option:selected').val();
            if(salonId!=""){
                productsearch(1,"",salonId,temp);
            }
            /*if(userKey!=""){
                var userKeyValue = $('.userKeyValue').val();
                var temp = userKey+"='"+userKeyValue+"'";
                productsearch(1, temp);
            }else{
                productsearch(1);
            }*/

        })
        $(".tingzhi").on("click",function(){
            var data = layui.table.checkStatus('layui_table_id').data;
            if(data.length>1||data.length<1){
                alert("请选中一条数据");
                return false;
            }
            $.ajax({
                type:'POST',
                url:'',
                data: {userId:data[0].recordId},
                success: function(data){
                    alert("操作成功！");
                    productsearch(1);
                },
                error:function(data){
                    alert("操作失败");
                    console.log(data);
                }
            })
        })

        function timeSeetingItem (data) {

            layer.open({
                type:2,
                area:[882+'px',915+'px'],
                fix:false,
                offset: '80px',
                maxmin:true,
                shadeClose:true,
                scrollbar: false,
                shade:0.4,
                title:'个人考勤',
                content:['stuff_timeSheetDetails.html'],
                success:function(layero,index){
                    var iframe = window['layui-layer-iframe' + index];
                    // 向子页面的全局函数child传参
                    iframe.child(data);
                    console.log("成功");
                },
                fail:function(data){
                    console.log(data);
                }
            })
        }


    });

</script>
